<!--
 * @Description: 
 * @Date: 2023-12-20 14:19:12
 * @LastEditTime: 2024-04-17 14:30:11
-->
<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import * as echarts from "echarts";
require("echarts/theme/shine"); // echarts theme
import resize from "../../../dashboard/mixins/resize";

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "100%",
    },
    chartData: {
      type: Object,
      required: false,
    },
  },

  data() {
    return {
      chart: null,
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart(data) {
      if (!this.chart) {
        this.chart = echarts.init(this.$el, "macarons");
      }
      this.chart &&
        this.chart.setOption({
          legend: {
            bottom: 20,
            textStyle: {
              color: "#fff",
              fontSize: 16,
            },
            data: ["年龄人数"],
          },
          grid: {
            left: "3%",
            right: "4%",
            bottom: "15%",
            top: "5%",
            containLabel: true,
          },

          tooltip: {
            show: "true",
            trigger: "item",
            axisPointer: {
              // 坐标轴指示器，坐标轴触发有效
              type: "line", // 默认为直线，可选为：'line' | 'shadow'
            },
          },
          xAxis: {
            type: "value",
            axisTick: { show: true },
            axisLine: {
              show: true,
              lineStyle: {
                color: "#fff",
              },
            },
            splitLine: {
              show: false,
            },
          },
          yAxis: {
            type: "category",
            axisTick: { show: false },
            axisLine: {
              show: true,
              lineStyle: {
                color: "#fff",
              },
            },
            data: ["18_30", "30-40", "40-50", "50-60", "60以上"],
          },
          series: [
            {
              name: "年龄人数",
              type: "bar",
              itemStyle: {
                normal: {
                  show: true,
                  color: "#277ace",
                  barBorderRadius: 50,
                  borderWidth: 0,
                  borderColor: "#333",
                },
              },
              barGap: "0%",
              barCategoryGap: "50%",
              data: [120, 132, 101, 134, 90],
            },
          ],
        });
    },
  },
};
</script>
<style lang="scss" scoped>
.pie2 {
  width: 100%;
  height: 100%;
}
</style>
